package com.eascs.fp.article.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.finance.admin.common.entity.ArticleEntity;
import com.eascs.finance.admin.common.entity.ArticleItemEntity;
import com.eascs.finance.admin.common.service.IArticlefoService;
import com.eascs.finance.admin.common.vo.ArticleQueryVO;
import com.eascs.fp.common.controller.BaseMasterViewController;
import com.eascs.site.view.ViewContext;

@Controller
@RequestMapping(value="/article")
public class ArticleShowController extends BaseMasterViewController{
	@Reference
	IArticlefoService articlefoService;
	
	@RequestMapping(value="/index")
	public String index(ArticleQueryVO vo) {
		try {
			List<ArticleItemEntity> articleItemList = articlefoService.getArticleItemList();
			if (!StringUtils.isNotEmpty(vo.getItemId())) {
				vo.setItemId(articleItemList.get(0).getId());
			}
			PageResult<ArticleEntity> frontArticleInfo = articlefoService.findFrontArticleInfo(vo);
			ViewContext.put("ArticlesInfo", frontArticleInfo);
			ViewContext.put("articleItemList", articleItemList);
			ArticleItemEntity item = new ArticleItemEntity();
			item.setId(vo.getItemId());
			ViewContext.put("item", item);
		} catch (Exception e) {}
		return "/article/exhibit";
	}
	
	@RequestMapping(value="/showContent")
	public String getContent(String articleId) {
		try {
			List<ArticleItemEntity> articleItemList = articlefoService.getArticleItemList();
			articlefoService.updateReadNum(articleId);
			ArticleEntity article = articlefoService.findArticleById(articleId);
			ArticleItemEntity item = new ArticleItemEntity();
			item.setId(article.getItemId());
			ViewContext.put("item", item);
			ViewContext.put("articleItemList", articleItemList);
			ViewContext.put("article", article);
            ViewContext.put("Desc",article.getArticleDesc());
            ViewContext.put("Keywords", article.getArticleKeywords());
		
		} catch (Exception e) {}
		
		return "/article/detail";
	}
	
}
